<?php

namespace pmvc\data\validation;

/**
 * An implementation of the {@link Validator}
 * interface that uses a provided closure to
 * validate values.
 */
class ClosureValidator
	implements Validator {

	private $fun = null;

	/**
	 * Creates the {@link Validator} with the
	 * given closure.
	 * @param callback $fun
	 */
	public function __construct($fun) {
		$this->fun = $fun;
	}

	/**
	 * {@inheritDoc}
	 * @see pmvc\data\validation.Validator::validate()
	 */
	public function validate($input) {
		$fun = $this->fun;
		return $fun($input);
	}

}

?>